#!/usr/bin/env python
# Create: 2019/1/9
__author__ = '749B'
"""基于装饰器2"""
from twisted.web.client import getPage, defer
from twisted.internet import reactor


def all_done(arg):
    print("All Done")
    reactor.stop()


def one_done(response):
    print(response)


@defer.inlineCallbacks
def task():
    for url in url_list:
        deferred = getPage(bytes(url, encoding='utf-8'))
        deferred.addCallback(one_done)
        yield deferred


url_list = [
    'http://www.bing.com',
    'http://www.baidu.com',
    'http://edu.51cto.com',
]

ret = task()
ret.addBoth(all_done)

if __name__ == '__main__':
    reactor.run()
